package com.itheima;

/**
 * 2025/4/18 20:25
 */
public class SilverCard extends Card{

    private static final double DISCOUNT = 0.9;

    public SilverCard(String carNumber, String name, String phone, double balance) {
        //判断充值的金额是否大于等于2000元，否则不创建对象
        if (balance >= 2000){
            //如何把传递的参数赋值给当前对象的属性
            setCarNumber(carNumber);
            setName(name);
            setPhone(phone);
            setBalance(balance);
        }else {
            System.out.println("卡余额必须大于等于2000元，才能创建对象");
        }
    }

    @Override
    public void charge(double money) {
        //判断充值的金额是否大于等于2000元，否则不充值
        if (money >= 2000){
            //如何把传递的参数赋值给当前对象的属性
            setBalance(getBalance() + money);
            System.out.println(this+"充值成功");
        }else {
            System.out.println("卡余额必须大于等于2000元，才能充值");
        }
    }

    @Override
    public boolean pay(double money) {
        //计算折扣后消费的金额
        money *= DISCOUNT;
        //获取当前的余额
        double balance = getBalance();
        //判断余额是否充足
        if (balance >= money) {
            //重新给父类中balance变量赋值
            balance -= money;
            //给父类中balance变量赋值
            setBalance(balance);
            System.out.println(this + "支付成功:"+money);
            return true;
        }else {
            System.out.println(this+"支付失败,请充值！");
            return false;
        }
    }

}
